package com.leetcode.algorithm.y22.m07.w4;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 1823. 找出游戏的获胜者
 * 
 * https://leetcode.cn/problems/find-the-winner-of-the-circular-game/
 * 
 * @author jie.deng
 *
 */
class Question1823Solution01 {

	public int findTheWinner(int n, int k) {
		Queue<Integer> queue = new LinkedList<>();
		for (int i = 1; i <= n; i++) {
			queue.offer(i);
		}
		while (queue.size() > 1) {
			int cnt = 1;
			while (cnt < k) {
				queue.offer(queue.poll());
				cnt++;
			}
			queue.poll();
		}
		return queue.peek().intValue();
	}

}